/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import javax.swing.JOptionPane;
import src.Core;

/**
 *
 * @author Strauzen
 */
public class VentanaPersonaje extends javax.swing.JFrame {

    Ventana1 v1;
    Ventana3 v3;
    Ventana4 v4;
    
    /**
     * Creates new form VentanaPersonaje
     */
    public VentanaPersonaje(Ventana1 v1, Ventana3 v3, Ventana4 v4) {
        this.v1 = v1;
        this.v3 = v3;
        this.v4 = v4;
        initComponents();
    }

    private boolean comprobar(){
        String mensaje = "";
        boolean resultado = false;
        
        if (this.jTextField_vpNombApe.getText().equals(""))
            mensaje += "Por favor rellene el campo de nombre y apellidos\n\n";
        if (this.jTextField_vpLugarNaci.getText().equals(""))
            mensaje += "Por facor rellene el campo de lugar de nacimiento\n\n";
        if (this.jTextField_vpLugarNaci.getText().equals(""))
            mensaje += "Por facor rellene el campo de lugar de nacimiento\n\n";
        if (this.jTextField_vpBiografia.getText().equals(""))
            mensaje += "Por favor rellene el campo de biografía\n\n";
        if(!mensaje.equals(""))
            JOptionPane.showMessageDialog(null, mensaje);
        else
            resultado = true;
        
        try{
            Integer.parseInt(this.jTextField_vpFechaNaci.getText());
            Integer.parseInt(this.jTextField_vpFechaDefun.getText());
            if(this.jTextField_vpFechaNaci.getText().length() != 8 || this.jTextField_vpFechaDefun.getText().length() != 8)
                throw new Exception();
            
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Por favor rellene las fechas de la siguiente manera:\n"
                    + "ej. 20120101 siendo los 4 primeros numeros el año, los dos siguientes el mes\n"
                    + "y los dos ultimos el día\n\n");
            resultado = false;
        }
              
        return resultado;
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel_vpNombApe = new javax.swing.JLabel();
        jTextField_vpNombApe = new javax.swing.JTextField();
        jLabel_vpFechaNaci = new javax.swing.JLabel();
        jTextField_vpFechaNaci = new javax.swing.JTextField();
        jLabel_vpLugarNaci = new javax.swing.JLabel();
        jTextField_vpLugarNaci = new javax.swing.JTextField();
        jLabel_vpFechaDefun = new javax.swing.JLabel();
        jTextField_vpFechaDefun = new javax.swing.JTextField();
        jLabel_vpLugarDefun = new javax.swing.JLabel();
        jTextField_vpLugarDefun = new javax.swing.JTextField();
        jLabel_vpBiografia = new javax.swing.JLabel();
        jTextField_vpBiografia = new javax.swing.JTextField();
        jButton_vpAlias = new javax.swing.JButton();
        jButton_vpCargo = new javax.swing.JButton();
        jButton_vpTerminar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Añadir Personaje");
        setName("Añadir Personaje"); // NOI18N

        jLabel_vpNombApe.setText("Nombre y Apellidos");

        jLabel_vpFechaNaci.setText("Fecha de Nacimiento");

        jLabel_vpLugarNaci.setText("Lugar de Nacimiento");

        jLabel_vpFechaDefun.setText("Fecha de Defuncion");

        jLabel_vpLugarDefun.setText("Lugar de Defuncion");

        jLabel_vpBiografia.setText("Biografia");

        jButton_vpAlias.setText("Añadir Alias");
        jButton_vpAlias.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_vpAliasMouseClicked(evt);
            }
        });

        jButton_vpCargo.setText("Añadir Cargo");
        jButton_vpCargo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_vpCargoMouseClicked(evt);
            }
        });

        jButton_vpTerminar.setText("Terminar");
        jButton_vpTerminar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_vpTerminarMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vpNombApe)
                    .addComponent(jLabel_vpFechaNaci)
                    .addComponent(jLabel_vpLugarNaci)
                    .addComponent(jLabel_vpFechaDefun)
                    .addComponent(jLabel_vpLugarDefun))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField_vpFechaDefun, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
                    .addComponent(jTextField_vpLugarNaci, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
                    .addComponent(jTextField_vpFechaNaci, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
                    .addComponent(jTextField_vpNombApe, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
                    .addComponent(jTextField_vpLugarDefun, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel_vpBiografia)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField_vpBiografia, javax.swing.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jButton_vpAlias, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 72, Short.MAX_VALUE)
                .addComponent(jButton_vpCargo, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(150, 150, 150)
                .addComponent(jButton_vpTerminar)
                .addContainerGap(168, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vpNombApe)
                    .addComponent(jTextField_vpNombApe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vpFechaNaci)
                    .addComponent(jTextField_vpFechaNaci, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vpLugarNaci)
                    .addComponent(jTextField_vpLugarNaci, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vpFechaDefun)
                    .addComponent(jTextField_vpFechaDefun, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vpLugarDefun)
                    .addComponent(jTextField_vpLugarDefun, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_vpBiografia)
                    .addComponent(jTextField_vpBiografia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_vpAlias)
                    .addComponent(jButton_vpCargo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_vpTerminar)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_vpTerminarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_vpTerminarMouseClicked
        // TODO add your handling code here:
        if(comprobar())
        {
            v3.setVisible(true);
            this.setVisible(false);
            int p = Core.CrearPersonaje(jTextField_vpNombApe.getText(), jTextField_vpFechaNaci.getText(), jTextField_vpLugarNaci.getText(),
                                jTextField_vpFechaDefun.getText(), jTextField_vpLugarDefun.getText(),
                                jTextField_vpBiografia.getText());
            Core.linkaPersonajeConDocumento(Core.getDocumento(),p);
            this.dispose();
        }
    }//GEN-LAST:event_jButton_vpTerminarMouseClicked

    private void jButton_vpAliasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_vpAliasMouseClicked
        // TODO add your handling code here:
        this.setVisible(false);
        VentanaAlias val = new VentanaAlias(this);
        val.setVisible(true);
    }//GEN-LAST:event_jButton_vpAliasMouseClicked

    private void jButton_vpCargoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_vpCargoMouseClicked
        // TODO add your handling code here:
        this.setVisible(false);
        v4.setVisible(true);
        v4.setPadre(4);
    }//GEN-LAST:event_jButton_vpCargoMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_vpAlias;
    private javax.swing.JButton jButton_vpCargo;
    private javax.swing.JButton jButton_vpTerminar;
    private javax.swing.JLabel jLabel_vpBiografia;
    private javax.swing.JLabel jLabel_vpFechaDefun;
    private javax.swing.JLabel jLabel_vpFechaNaci;
    private javax.swing.JLabel jLabel_vpLugarDefun;
    private javax.swing.JLabel jLabel_vpLugarNaci;
    private javax.swing.JLabel jLabel_vpNombApe;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField_vpBiografia;
    private javax.swing.JTextField jTextField_vpFechaDefun;
    private javax.swing.JTextField jTextField_vpFechaNaci;
    private javax.swing.JTextField jTextField_vpLugarDefun;
    private javax.swing.JTextField jTextField_vpLugarNaci;
    private javax.swing.JTextField jTextField_vpNombApe;
    // End of variables declaration//GEN-END:variables
}
